#include <sxComponent.h>

Sx::Interface::Component::Component() {}
Sx::Interface::Component::~Component() {}

bool Sx::Interface::Component::addKeyListener(KeyListener* listener) {
	if ( listener == nullptr ) {
		std::cerr << "[Component:addKeyListener] Error: Cannot add nullptr key listener to component." << std::endl;
		std::cerr << "  No listener added." << std::endl;
		return false;
	}

	if ( this->keyListeners.contains(listener) ) {
		std::cerr << "[Component:addKeyListener] Error: Provided key listener already registered with this component." << std::endl;
		std::cerr << "  No listener added." << std::endl;
		return false;
	}

	this->keyListeners.addLast(listener);
	return true;
}

bool Sx::Interface::Component::addMouseListener(MouseListener* listener) {
	if ( listener == nullptr ) {
		std::cerr << "[Component:addMouseListener] Error: Cannot add nullptr mouse listener to component." << std::endl;
		std::cerr << "  No listener added." << std::endl;
		return false;
	}

	if ( this->mouseListeners.contains(listener) ) {
		std::cerr << "[Component:addMouseListener] Error: Provided mouse listener already registered with this component." << std::endl;
		std::cerr << "  No listener added." << std::endl;
		return false;
	}

	this->mouseListeners.addLast(listener);
	return true;
}

bool Sx::Interface::Component::removeKeyListener(KeyListener* listener) {
	if ( listener == nullptr ) return false;
	return this->keyListeners.remove(listener);
}

bool Sx::Interface::Component::removeMouseListener(MouseListener* listener) {
	if ( listener == nullptr ) return false;
	return this->mouseListeners.remove(listener);
}

Sx::Graphics::Rectanglei Sx::Interface::Component::getView() const {
	return this->view;
}
